import { getCache, setCache } from '@/utils/cache'
import request from '@/utils/request'

enum Api {
  GetCode = '/api/Uniform/xcode'
}

export async function GetCodeApi() {
  let uuid = getCache('x-uuid')
  if (!uuid) {
    uuid = Math.random().toString(36).substring(3, 8)
    setCache('x-uuid', uuid, true)
  }

  const data = await request.post(
    Api.GetCode,
    {},
    { headers: { 'x-uuid': uuid }, responseType: 'arraybuffer' }
  )
  const blob = new Blob([data], { type: 'image/png' })
  return URL.createObjectURL(blob)
}
